package com.ymatou.iapi.userservice.testcase;

import java.util.Iterator;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.SetRemarkBean;
import com.ymatou.iapi.userservice.service.SetRemarkCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.constant.ECode;
/**
*修改用户简介
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetRemark{
	private static SetRemarkBean setremarkBean;
	private static SetRemarkCall setremarkCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改用户简介");
	}

	@Before
	public void caseUp() {
		setremarkBean=new SetRemarkBean();
		setremarkCall=new SetRemarkCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setremarkCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRemark_001() {
		Logger.start(true,"修改用户简介成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = result.get("Token").getAsString();
			int uid = urrc.getUserid();
			setremarkBean.setRemark("测试Remark");
			setremarkBean.setUserId(uid);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", setremarkCall.getString("Success"), "验证操作是否成功");
//			Logger.verifyEquals("ok", setnicknamedtoCall.getString("Result"), "验证绑定成功");
			Userinfoex info = new JUserWapper().selectUserinfoexByUid(uid).get(0);
			Logger.verifyEquals(setremarkBean.getRemark(),  info.getRemark(), "验证Remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRemark_002() {
		Logger.start(true,"不输入uid，失败");
		try {
			setremarkBean.setRemark("测试Remark");
//			setremarkBean.setUserId(uid);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals("100", setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", setremarkCall.getString("Success"), "验证操作是否成功");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRemark_003() {
		Logger.start(true,"不输入Remark，失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = result.get("Token").getAsString();
			int uid = urrc.getUserid();
//			setremarkBean.setRemark("测试Remark");
			setremarkBean.setUserId(2);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals("200", setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", setremarkCall.getString("Success"), "验证操作是否成功");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRemark_004() {
		Logger.start(true,"输入Remark超长，失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = result.get("Token").getAsString();
			int uid = urrc.getUserid();
			String remark="";
			for (int i = 0; i < 50; i++) {
				remark+="too long:";
			}
			setremarkBean.setRemark(remark);
			setremarkBean.setUserId(uid);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals("100", setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", setremarkCall.getString("Success"), "验证操作是否成功");	
			Logger.verifyIsContains("超过长度限制", setremarkCall.getString("LastErrorMessage"), "验证LastErrorMessage");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRemark_005() {
		Logger.start(true,"输入不存在的uid，失败");
		try {
			setremarkBean.setRemark("remark");
			setremarkBean.setUserId(-1000);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals("100", setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", setremarkCall.getString("Success"), "验证操作是否成功");	
			Logger.verifyIsContains("无效的用户编号", setremarkCall.getString("LastErrorMessage"), "验证LastErrorMessage");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//待确认
	public void Tc_SetRemark_006() {
		Logger.start(true,"输入Remark包含敏感词，失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = result.get("Token").getAsString();
			int uid = urrc.getUserid();
			setremarkBean.setRemark("洋码头官方客服");
			setremarkBean.setUserId(uid);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", setremarkCall.getString("Success"), "验证操作是否成功");
//			Logger.verifyEquals("ok", setnicknamedtoCall.getString("Result"), "验证绑定成功");
			Userinfoex info = new JUserWapper().selectUserinfoexByUid(uid).get(0);
			Logger.verifyEquals(setremarkBean.getRemark(),  info.getRemark(), "验证Remark");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRemark_007() {
		Logger.start(true,"简介包含表情修改用户简介成功utf8mb4_unicode_ci");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = result.get("Token").getAsString();
			int uid = urrc.getUserid();
			setremarkBean.setRemark("22:;;;;😑😊😳");
			setremarkBean.setUserId(uid);
			setremarkCall.setData(setremarkBean);
			setremarkCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, setremarkCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", setremarkCall.getString("Success"), "验证操作是否成功");
//			Logger.verifyEquals("ok", setnicknamedtoCall.getString("Result"), "验证绑定成功");
			Userinfoex info = new JUserWapper().selectUserinfoexByUid(uid).get(0);
			Logger.verifyEquals(setremarkBean.getRemark(),  info.getRemark(), "验证Remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}